﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using JumbotPay.API.YunGouOS.WxPay;
namespace JumbotPay.WebFile.YungGouOS_Wxpay_Mobile
{
    public partial class _notify_url : JumbotPay.UI.BasicPage
    {
        public string account_wxpay = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Charset = "utf-8";
            Response.ContentType = "text/xml";
            account_wxpay = q("account_no");//可以获取



            WxPayConfig conf = new WxPayConfig(account_wxpay);
            WxPayData notifyData = new WxPayData();
            notifyData.SetValue("code", f("code"), true);
            notifyData.SetValue("orderNo", f("orderNo"), true);
            notifyData.SetValue("outTradeNo", f("outTradeNo"), true);
            notifyData.SetValue("payNo", f("payNo"), true);
            notifyData.SetValue("money", f("money"), true);
            notifyData.SetValue("mchId", f("mchId"), true);
            notifyData.SetValue("payChannel", f("payChannel"), false);
            notifyData.SetValue("time", f("time"), false);
            notifyData.SetValue("attach", f("attach"), false);
            notifyData.SetValue("openId", f("openId"), false);



            notifyData.SetValue("sign", f("sign"), false);

            JumbotPay.Utils.Logs.Info("wxpayM_notify", notifyData.ToJson(), false);

            if (notifyData.CheckSign_Must(conf.KEY))
            {
                if (notifyData.GetValue("code").ToString() == "1")//支付通知
                {
                    string _out_trade_no = notifyData.GetValue("attach").ToString();
                    new JumbotPay.DAL.OrderDAL().UpdateOrder("yungouos_wxpay", _out_trade_no, _out_trade_no, "");
                    Response.Write("SUCCESS");
                    Response.End();
                }
                else
                {
                    JumbotPay.Utils.Logs.Error("wxpayM_notify", "签名失败：" + notifyData.ToJson(), false);
                    Response.Write("签名验证失败");
                    Response.End();
                }
            }
            else
            {
                JumbotPay.Utils.Logs.Error("wxpayM_notify", "签名失败：" + notifyData.ToJson(), false);
                Response.Write("签名验证失败");
                Response.End();
            }
        }
    }
}